package main

import "fmt"

// defer面试题
func calc(index string, a, b int) int {
	ret := a + b
	fmt.Println(index, a, b, ret)
	return ret
}

func main() {
	x := 1
	y := 2
	defer calc("AA", x, calc("A", x, y))
	x = 10
	defer calc("BB", x, calc("B", x, y))
	y = 20
}

/*
压栈过程
AA --- 压栈时要确定参数,执行calc("B", x, y)
^
BB --- 压栈时要确定参数,执行calc("A", x, y)
弹栈过程
AA --- 弹栈,执行calc("AA", x, calc("A", x, y))
^
BB --- 弹栈,执行calc("BB", x, calc("B", x, y))


A 1 2 3
B 10 2 12
BB 10 12 22
AA 1 3 4
*/
